package com.example.springsecurityoauth2demo.config;

import com.example.springsecurityoauth2demo.service.UserDetailsServiceImpl;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer;
import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerConfigurerAdapter;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer;
import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerEndpointsConfigurer;

import javax.annotation.Resource;

/**
 * @Classname: aa
 * @Description: 授权服务器配置
 * @Date: 2021/3/18 21:35
 * @Created: by Wang Xu
 */
@Configuration
@EnableAuthorizationServer
public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdapter {



    @Resource
    private PasswordEncoder passwordEncoder;



    @Override
    public void configure(ClientDetailsServiceConfigurer clients) throws Exception {

        clients
                // 保存在内存中
                .inMemory()
                // client-id
                .withClient("admin")
                // 配置client-secret
                .secret(passwordEncoder.encode("112233"))
                // 配置访问token的有效期
//                .accessTokenValiditySeconds(3600)
                // 配置授权成功后的跳转页面
                .redirectUris("http://www.ipaso.cn")
                // 配置申请的授权范围
                .scopes("all")
                // 配置授权模式 授权码模式
                .authorizedGrantTypes("authorization_code");
    }
}
